In [1]:
#%matplotlib inline
import pandas as pd
import platform
import sys
import numpy as np
from datetime import datetime, date, timedelta
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
import matplotlib
#from pylab import rcParams
#rcParams['figure.figsize'] = 15, 10

In [2]:
import wellapplication as wa

In [3]:
print("Operating System " + platform.system() + " " + platform.release())
print("Python Version " + str(sys.version))
print("Pandas Version " + str(pd.__version__))
print("Numpy Version " + str(np.__version__))
print("Matplotlib Version " + str(matplotlib.__version__))
print("Well Application Version " + str(wa.__version__))


Operating System Windows 7
Python Version 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)]
Pandas Version 0.17.1
Numpy Version 1.10.4
Matplotlib Version 1.5.1
Well Application Version 0.2.5

Call usgs class of wellapplication


In [4]:
USGS = wa.usgs()

Set working environment.


In [ ]:
rootlocal = 'E:/GIS/'

Read in data prepared by ArcGIS.


In [5]:
matchedStations = pd.read_csv(rootlocal + "USGS_WL_WELLS_HUCS.txt")

Show columns in imported column.


In [6]:
matchedStations.columns


Out[6]:
Index([u'OBJECTID', u'Join_Count', u'TARGET_FID', u'agency_cd', u'station_nm',
       u'site_tp_cd', u'dec_lat_va', u'dec_long_va', u'coord_acy_cd',
       u'dec_coord_datum_cd', u'alt_va', u'alt_acy_va', u'alt_datum_cd',
       u'huc_cd', u'UTM_X', u'UTM_Y', u'site_no', u'TNMID', u'GNIS_ID',
       u'AreaAcres', u'AreaSqKm', u'HUC12', u'Name', u'ToHUC',
       u'NonContributingAcres', u'NonContributingSqKm', u'HUC10', u'HUC8',
       u'GWArea'],
      dtype='object')

Get list of stations for each groundwater area.


In [7]:
stationLists = matchedStations.groupby(['GWArea'])['site_no'].unique()

Create dictionary matching HUC names to HUC 8 codes.


In [9]:
nameit = pd.Series(matchedStations.Name.values, index = matchedStations.HUC8).to_dict()

Generate site and data files from HUC 8 in list.


In [ ]:
sites = {}
data = {}

areaList = list(matchedStations.HUC8.unique())[1:]

for area in areaList:
    try:
        sites[area] = USGS.getStationInfoFromHUC(area)
        data[area] = USGS.getWLfromHUC(area)
        print area
    except:
        print("no data for " + str(area))
        pass

Combine dictionaries into a complete data and stations file.


In [ ]:
allsites = pd.concat(sites)
alldata = pd.concat(data)

Save files as csv files and an excel file.


In [ ]:
allsites.to_csv(rootlocal + 'USGSSites.csv')
alldata.to_csv(rootlocal + 'USGSData.csv')

In [ ]:
writer = ExcelWriter(rootlocal + 'USGS_WL_UT.xlsx')
allsites.to_excel(writer,'sites')
alldata.to_excel(writer,'data')
writer.save()

Generate and save plots to a pdf file. Skip error files.


In [ ]:
pdf_pages = PdfPages(rootlocal + 'HydrographSummary.pdf')

for area in areaList:
    try:
        plots = USGS.HUCplot(sites[area],data[area]) 
        fig = plots[0]
        fig.suptitle(str(area) + " = " + nameit[area])
        pdf_pages.savefig(fig)
        plt.close(fig)
        fig2 = plots[1]
        fig2.suptitle(str(area) + " = " + nameit[area])
        pdf_pages.savefig(fig2)
        plt.close(fig2)
        print(str(area) + " = " + nameit[area])
    except:
        print("no plot for " + str(area) + " = " + str(nameit[area]))
        pass
        

# Write the PDF document to the disk
pdf_pages.close()

In [ ]:
area = 16020302
pdf_pages = PdfPages(rootlocal + 'E:/GIS/HydrographSummarySingle.pdf')
plots = USGS.HUCplot(sites[area],data[area]) 
fig = plots[0]
fig.suptitle(str(area) + " = " + nameit[area])
pdf_pages.savefig(fig)
plt.close(fig)
fig2 = plots[1]
fig2.suptitle(str(area) + " = " + nameit[area])
pdf_pages.savefig(fig2)
plt.close(fig2)
print(str(area) + " = " + nameit[area])
pdf_pages.close()